package cn.edu.qfnu.oj.entity;

import com.google.common.base.Objects;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;

import javax.persistence.*;
import java.io.Serializable;


@Entity
@DynamicUpdate
@DynamicInsert
public class Attend implements Serializable {

    private static final long serialVersionUID = -3653052364957595535L;
    private Integer id;
    private Integer acceptCount;   //通过总数

    private Integer aACTime;
    private Integer aWrongSubmit;
    private Integer bACTime;
    private Integer bWrongSubmit;
    private Integer cACTime;
    private Integer cWrongSubmit;
    private Integer dACTime;
    private Integer dWrongSubmit;
    private Integer eACTime;
    private Integer eWrongSubmit;
    private Integer fACTime;
    private Integer fWrongSubmit;
    private Integer gACTime;
    private Integer gWrongSubmit;
    private Integer hACTime;
    private Integer hWrongSubmit;
    private Integer iACTime;
    private Integer iWrongSubmit;
    private Integer jACTime;
    private Integer jWrongSubmit;

    private Student student; // 学生记录 多对一关系
    private Contest contest; // 比赛记录 一对一关系
    private Task task; // 作业记录 一对一关系

    public Attend() {}

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Column(name = "accept_count")
    public Integer getAcceptCount() {
        return acceptCount;
    }

    public void setAcceptCount(Integer acceptCount) {
        this.acceptCount = acceptCount;
    }

    @Column(name = "A_AC_time")
    public Integer getAACTime() {
        return aACTime;
    }

    public void setAACTime(Integer aACTime) {
        this.aACTime = aACTime;
    }

    @Column(name = "A_WrongSubmit")
    public Integer getAWrongSubmit() {
        return aWrongSubmit;
    }

    public void setAWrongSubmit(Integer aWrongSubmit) {
        this.aWrongSubmit = aWrongSubmit;
    }

    @Column(name = "B_AC_time")
    public Integer getBACTime() {
        return bACTime;
    }

    public void setBACTime(Integer bACTime) {
        this.bACTime = bACTime;
    }

    @Column(name = "B_WrongSubmit")
    public Integer getBWrongSubmit() {
        return bWrongSubmit;
    }

    public void setBWrongSubmit(Integer bWrongSubmit) {
        this.bWrongSubmit = bWrongSubmit;
    }

    @Column(name = "C_AC_time")
    public Integer getCACTime() {
        return cACTime;
    }

    public void setCACTime(Integer cACTime) {
        this.cACTime = cACTime;
    }

    @Column(name = "C_WrongSubmit")
    public Integer getCWrongSubmit() {
        return cWrongSubmit;
    }

    public void setCWrongSubmit(Integer cWrongSubmit) {
        this.cWrongSubmit = cWrongSubmit;
    }

    @Column(name = "D_AC_time")
    public Integer getDACTime() {
        return dACTime;
    }

    public void setDACTime(Integer dACTime) {
        this.dACTime = dACTime;
    }

    @Column(name = "D_WrongSubmit")
    public Integer getDWrongSubmit() {
        return dWrongSubmit;
    }

    public void setDWrongSubmit(Integer dWrongSubmit) {
        this.dWrongSubmit = dWrongSubmit;
    }

    @Column(name = "E_AC_time")
    public Integer getEACTime() {
        return eACTime;
    }

    public void setEACTime(Integer eACTime) {
        this.eACTime = eACTime;
    }

    @Column(name = "E_WrongSubmit")
    public Integer getEWrongSubmit() {
        return eWrongSubmit;
    }

    public void setEWrongSubmit(Integer eWrongSubmit) {
        this.eWrongSubmit = eWrongSubmit;
    }

    @Column(name = "F_AC_time")
    public Integer getFACTime() {
        return fACTime;
    }

    public void setFACTime(Integer fACTime) {
        this.fACTime = fACTime;
    }

    @Column(name = "F_WrongSubmit")
    public Integer getFWrongSubmit() {
        return fWrongSubmit;
    }

    public void setFWrongSubmit(Integer fWrongSubmit) {
        this.fWrongSubmit = fWrongSubmit;
    }

    @Column(name = "G_AC_time")
    public Integer getGACTime() {
        return gACTime;
    }

    public void setGACTime(Integer gACTime) {
        this.gACTime = gACTime;
    }

    @Column(name = "G_WrongSubmit")
    public Integer getGWrongSubmit() {
        return gWrongSubmit;
    }

    public void setGWrongSubmit(Integer gWrongSubmit) {
        this.gWrongSubmit = gWrongSubmit;
    }

    @Column(name = "H_AC_time")
    public Integer getHACTime() {
        return hACTime;
    }

    public void setHACTime(Integer hACTime) {
        this.hACTime = hACTime;
    }

    @Column(name = "H_WrongSubmit")
    public Integer getHWrongSubmit() {
        return hWrongSubmit;
    }

    public void setHWrongSubmit(Integer hWrongSubmit) {
        this.hWrongSubmit = hWrongSubmit;
    }

    @Column(name = "I_AC_time")
    public Integer getIACTime() {
        return iACTime;
    }

    public void setIACTime(Integer iACTime) {
        this.iACTime = iACTime;
    }

    @Column(name = "I_WrongSubmit")
    public Integer getIWrongSubmit() {
        return iWrongSubmit;
    }

    public void setIWrongSubmit(Integer iWrongSubmit) {
        this.iWrongSubmit = iWrongSubmit;
    }

    @Column(name = "J_AC_time")
    public Integer getJACTime() {
        return jACTime;
    }

    public void setJACTime(Integer jACTime) {
        this.jACTime = jACTime;
    }

    @Column(name = "J_WrongSubmit")
    public Integer getJWrongSubmit() {
        return jWrongSubmit;
    }

    public void setJWrongSubmit(Integer jWrongSubmit) {
        this.jWrongSubmit = jWrongSubmit;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Attend attend = (Attend) o;
        return Objects.equal(id, attend.id) &&
                Objects.equal(acceptCount, attend.acceptCount) &&
                Objects.equal(aACTime, attend.aACTime) &&
                Objects.equal(aWrongSubmit, attend.aWrongSubmit) &&
                Objects.equal(bACTime, attend.bACTime) &&
                Objects.equal(bWrongSubmit, attend.bWrongSubmit) &&
                Objects.equal(cACTime, attend.cACTime) &&
                Objects.equal(cWrongSubmit, attend.cWrongSubmit) &&
                Objects.equal(dACTime, attend.dACTime) &&
                Objects.equal(dWrongSubmit, attend.dWrongSubmit) &&
                Objects.equal(eACTime, attend.eACTime) &&
                Objects.equal(eWrongSubmit, attend.eWrongSubmit) &&
                Objects.equal(fACTime, attend.fACTime) &&
                Objects.equal(fWrongSubmit, attend.fWrongSubmit) &&
                Objects.equal(gACTime, attend.gACTime) &&
                Objects.equal(gWrongSubmit, attend.gWrongSubmit) &&
                Objects.equal(hACTime, attend.hACTime) &&
                Objects.equal(hWrongSubmit, attend.hWrongSubmit) &&
                Objects.equal(iACTime, attend.iACTime) &&
                Objects.equal(iWrongSubmit, attend.iWrongSubmit) &&
                Objects.equal(jACTime, attend.jACTime) &&
                Objects.equal(jWrongSubmit, attend.jWrongSubmit) &&
                Objects.equal(student, attend.student) &&
                Objects.equal(contest, attend.contest) &&
                Objects.equal(task, attend.task);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(id, acceptCount, aACTime, aWrongSubmit, bACTime, bWrongSubmit,
                cACTime, cWrongSubmit, dACTime, dWrongSubmit, eACTime, eWrongSubmit,
                fACTime, fWrongSubmit, gACTime, gWrongSubmit, hACTime, hWrongSubmit,
                iACTime, iWrongSubmit, jACTime, jWrongSubmit, student, contest, task);
    }

    //一个参与记录对应一个学生 而一个学生可以由多个提交记录
    //因此参与记录与学生是多对一关系
    @ManyToOne // 维护参与记录与学生的多对一关系
    @JoinColumn(name = "student_id", referencedColumnName = "student_id")
    public Student getStudent() {
        return student;
    }

    public void setStudent(Student student) {
        this.student = student;
    }

    // 一次比赛对应一个参与记录 而一个参与记录只对应一个比赛
    // 因此参与记录于比赛是一对一关系
    @OneToOne // 维护比赛与提交记录的一对一关系
    @JoinColumn(name = "contest_id", referencedColumnName = "id")
    public Contest getContest() {
        return contest;
    }

    public void setContest(Contest contest) {
        this.contest = contest;
    }

    // 一次作业对应一个比赛记录 而一个参与记录只对应一次作业
    // 因此参与记录与作业之间是一对一关系
    @OneToOne // 维护作业与参与记录的一对一关系
    @JoinColumn(name = "task_id", referencedColumnName = "id")
    public Task getTask() {
        return task;
    }

    public void setTask(Task taskByTaskId) {
        this.task = taskByTaskId;
    }
}
